package com.cn.hangyun.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cn.hangyun.common.CustomerContextHolder;
import com.cn.hangyun.dao.MemberMapper;
import com.cn.hangyun.model.Member;
import com.cn.hangyun.service.IMemberService;

@Service("memberService")
public class MemberServiceImpl implements IMemberService {

	private MemberMapper memberMapper;

	public MemberMapper getMemberMapper() {
		return memberMapper;
	}

	@Autowired
	public void setMemberMapper(MemberMapper memberMapper) {
		this.memberMapper = memberMapper;
	}

	@Override
	public Member getMemberByNm(String userNm) {
		//CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_SQL);
		return memberMapper.selectByUserNmKey(userNm);
	}

	@Override
	public int updateUserPw(Member memberParam) {
		CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_PG);
		return memberMapper.updateByUserNm(memberParam);
	}

	@Override
	public List<Member> getMemberAll() {
		CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_PG);
		return memberMapper.selectByUserAll();
	}

	@Override
	public Member getMemberByid(Integer uid) {
		CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_PG);
		return memberMapper.selectByUserKey(uid);
	}

	@Override
	public int updateMember(Member memberP) {
		CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_PG);
		return memberMapper.updateMember(memberP);
	}

	@Override
	public int insert(Member memberP) {
		CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_PG);
		return memberMapper.insert(memberP);
	}

	@Override
	public void deleteById(Integer uid) {
		CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_PG);
		memberMapper.deleteByUid(uid);
	}

}
